#include<head.h>

int main(int argc, char const *argv[])
{
    pid_t pid = fork();
    int wait_read = 0;
    if(-1 ==pid)
    {
        perror("fork");
        return 1;
    }
    if(pid == 0) // 子进程
    {
        printf("子进程 = %d\n",getpid());
        sleep(30);
        printf("子进程结束\n");
        exit(5);
    }
    else
    {
        printf("父进程 = %d\n", getpid());
        kill(pid, SIGSTOP); // 暂停子进程
        sleep(1);
        kill(pid, SIGCONT); // 继续子进程
    }

    wait(&wait_read);
    if(WIFEXITED(wait_read))
    {
        printf("子进程正常退出,退出码 = %d\n",WEXITSTATUS(wait_read));
    }
    else if(WIFSIGNALED(wait_read))
    {
        printf("子进程异常退出,信号 = %d\n",WTERMSIG(wait_read));
    }
    else if(WIFSTOPPED(wait_read))
    {
        printf("子进程暂停,信号 = %d\n",WSTOPSIG(wait_read)); //父进程向子进程发送Kill(pid,SIGTOP)信号暂停
    }

    else if(WIFCONTINUED(wait_read))
    {
        printf("子进程继续执行\n");
    }

    return 0;
}
